package com.hzx.shoot;

import com.hzx.shoot.img.Images;

import java.awt.image.BufferedImage;

/*
 * 敌人类 ：小敌人
 * */
public class Airplane extends FlyingObject {

    //速度
    public int speed;
    int index = 0; //=1

    @Override
    public String toString() {
        return "Airplane{" +
                "speed=" + speed +
                ", wdith=" + wdith +
                ", height=" + height +
                ", x=" + x +
                ", y=" + y +
                '}';
    }

    public Airplane() {
        this.wdith = 96;
        this.height = 74;
        this.x = (int) (Math.random() * (512 - this.wdith));
        this.y = -this.height;

        speed = 3;
    }

    @Override
    public BufferedImage getImage() {
        //游戏开始运行的状态应该为第一张
        if (state == LIVE) {
            //如果活的就要返回第一张图片
            return Images.airplaneImage[0];
        } else if (state == DEAD) {
            BufferedImage image = Images.airplaneImage[++index];//index++
            if (index == Images.airplaneImage.length) {//图片如果遍历到最后一张 就可以吧当前的对象进行移除
                state = REMOVE;
            }
            return image;
        }
        //当发生碰撞之后图片进行爆炸效果切换  从第一张开始遍历到第四张
        return null;
    }
}
